package com.jamlu.framework.utils;

import android.support.annotation.NonNull;

import com.jamlu.framework.model.bean.BaseBean;
import com.jamlu.framework.ui.status.IStatus;
import com.jamlu.framework.ui.status.RequestUtils;
import com.jamlu.framework.ui.status.StatusRequest;
import com.jamlu.framework.ui.status.StatusUtils;
import com.jamlu.framework.ui.view.IBaseView;

import io.reactivex.Observable;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;

/**
 * Created by DMing at 2018/3/8 0008
 */

public class RFDialogUtils {

    private static void injectStatusToast(IBaseView iBaseView, @NonNull StatusRequest statusRequest){
        StatusUtils.initStatusToast(iBaseView.getContext(),iBaseView.getPresenter().getDisposables(), statusRequest);
    }

    private static void injectStatusDialog(IBaseView iBaseView,@NonNull StatusRequest statusRequest){
        StatusUtils.initStatusDialog(iBaseView, iBaseView.getPresenter().getDisposables(), true, statusRequest);
    }

    private static void injectStatusDialog(IBaseView iBaseView,boolean cancelable,@NonNull StatusRequest statusRequest){
        StatusUtils.initStatusDialog(iBaseView, iBaseView.getPresenter().getDisposables(), cancelable, statusRequest);
    }
    ///////////////////////////////////////
    public static void requestStatusToast(IBaseView iBaseView,@NonNull final Observable requestObservable){
        injectStatusToast(iBaseView,new StatusRequest() {
            @Override
            public Disposable run(@NonNull IStatus iStatus) {
                return RequestUtils.request(requestObservable)
                        .iStatus(iStatus)
                        .listener();
            }
        });
    }

    public static void requestStatusDialog(IBaseView iBaseView,@NonNull final Observable requestObservable){
        injectStatusDialog(iBaseView,new StatusRequest() {
            @Override
            public Disposable run(@NonNull IStatus iStatus) {
                return RequestUtils.request(requestObservable)
                        .iStatus(iStatus)
                        .listener();
            }
        });
    }

    public static void requestStatusDialog(IBaseView iBaseView,boolean cancelable,@NonNull final Observable requestObservable){
        injectStatusDialog(iBaseView,cancelable,new StatusRequest() {
            @Override
            public Disposable run(@NonNull IStatus iStatus) {
                return RequestUtils.request(requestObservable)
                        .iStatus(iStatus)
                        .listener();
            }
        });
    }

    public static void requestStatusToast(IBaseView iBaseView,@NonNull final Observable requestObservable, @NonNull final Consumer<? extends BaseBean> consumer){
        injectStatusToast(iBaseView,new StatusRequest() {
            @Override
            public Disposable run(@NonNull IStatus iStatus) {
                return RequestUtils.request(requestObservable)
                        .iStatus(iStatus)
                        .listener(consumer);
            }
        });
    }

    public static void requestStatusDialog(IBaseView iBaseView,@NonNull final Observable requestObservable,@NonNull  final Consumer<? extends BaseBean> consumer){
        injectStatusDialog(iBaseView,new StatusRequest() {
            @Override
            public Disposable run(@NonNull IStatus iStatus) {
                return RequestUtils.request(requestObservable)
                        .iStatus(iStatus)
                        .listener(consumer);
            }
        });
    }

    public static void requestStatusDialog(IBaseView iBaseView,boolean cancelable,@NonNull final Observable requestObservable, @NonNull final Consumer<? extends BaseBean> consumer){
        injectStatusDialog(iBaseView,cancelable,new StatusRequest() {
            @Override
            public Disposable run(@NonNull IStatus iStatus) {
                return RequestUtils.request(requestObservable)
                        .iStatus(iStatus)
                        .listener(consumer);
            }
        });
    }

    public static void requestStatusToast(IBaseView iBaseView,@NonNull final Observable requestObservable, @NonNull final Consumer<? extends BaseBean> consumer, @NonNull final Consumer<Integer> failureStatus){
        injectStatusToast(iBaseView,new StatusRequest() {
            @Override
            public Disposable run(@NonNull IStatus iStatus) {
                return RequestUtils.request(requestObservable)
                        .iStatus(iStatus)
                        .listener(consumer,failureStatus);
            }
        });
    }

    public static void requestStatusDialog(IBaseView iBaseView,@NonNull final Observable requestObservable, @NonNull final Consumer<? extends BaseBean> consumer, @NonNull  final Consumer<Integer> failureStatus){
        injectStatusDialog(iBaseView,new StatusRequest() {
            @Override
            public Disposable run(@NonNull IStatus iStatus) {
                return RequestUtils.request(requestObservable)
                        .iStatus(iStatus)
                        .listener(consumer,failureStatus);
            }
        });
    }

    public static void requestStatusDialog(IBaseView iBaseView,boolean cancelable, @NonNull final Observable requestObservable, @NonNull final Consumer<? extends BaseBean> consumer, @NonNull final Consumer<Integer> failureStatus){
        injectStatusDialog(iBaseView,cancelable,new StatusRequest() {
            @Override
            public Disposable run(@NonNull IStatus iStatus) {
                return RequestUtils.request(requestObservable)
                        .iStatus(iStatus)
                        .listener(consumer,failureStatus);
            }
        });
    }


}
